package com.webframe.beanProcess;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.webframe.exception.JSException;


/**
 * 类功能描述：
 *
 * @author      <a href="mailto:tozxwu@hotmail.com">wuzhenxue </a>
 * Create:      2009-10-21 下午01:25:50
 * Description: 
 */
public class BeanPropertyMapAppender extends AbstractBeanPropertyProcessor {
	
	private static final Log log = LogFactory.getLog(BeanPropertyMapAppender.class);

	@SuppressWarnings("rawtypes")
	private Map appended;
	
	@SuppressWarnings({
				"rawtypes", "unchecked"})
	protected Object getProcessedPropertyValue(Object originalValue) {
		Map appendedValue;
		if (originalValue == null) {
			appendedValue = getAppended();
		} else {
			if (!(originalValue instanceof Map)) {
				throw new JSException("jsexception.property.not.a.map", new Object[] {getPropertyName(), getBeanName()});
			}
			appendedValue = (Map) originalValue;
			appendedValue.putAll(getAppended());
		}
		
		if (log.isInfoEnabled()) {
			log.info("Adding/overriding " + getAppended().size() + " entry(ies) to " + getBeanName() + "." + getPropertyName());
		}
		
		return appendedValue;
	}

	@SuppressWarnings("rawtypes")
	public Map getAppended() {
		return appended;
	}

	@SuppressWarnings("rawtypes")
	public void setAppended(Map appendedText) {
		this.appended = appendedText;
	}

}

